import torch
import numpy as np
import random


def set_random_seed(seed: int = 0) -> None:
    """Set random seed.
    Parameters
    ----------
    seed : int
        Random seed to use
    """
    random.seed(seed)
    np.random.seed(seed)
    torch.manual_seed(seed)
    if torch.cuda.is_available():
        torch.cuda.manual_seed(seed)


def get_device_list() -> list:
    """
    get available devices list in cpu and cuda. First number is device('cpu')
    :return: list of devices like [device(type='cpu'), device(type='cuda', index=0), device(type='cuda', index=1)]
    """
    if not torch.cuda.is_available():
        return [torch.device('cpu')]
    else:
        gpu_numbers = torch.cuda.device_count()
        device_list = [torch.device('cpu')]
        for gpu_number in range(gpu_numbers):
            device_list.append(torch.device('cuda:{}'.format(gpu_number)))
        return device_list
